<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
   <head>
    <meta charset="utf-8">
    <title>W3SCRIPTS - development for developers</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="W3SCRIPTS. Leading you to innovative Web Scripts">
    <meta name="author" content="Baseer Baheer">

    <!-- Le styles -->
    <link href="css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
    <link href="css/custom.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">

    <!--[if IE 7]>
      <link href="http://netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome-ie7.css" rel="stylesheet">
    <![endif]-->

    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script type="text/javascript" src="http://cdn.jsdelivr.net/html5shiv/3.6.1/html5shiv.min.js"></script>
    <![endif]-->
    
   <meta http-equiv="refresh" content="10,URL=login.php">
  </head>


  <body>

    <div class="container">
    

	    <div class="modal" id="loginModal">
	    
    <div class="modal-header">
    
    
        <!--<button type="button" class="close" data-dismiss="modal">?</button>-->
        <a href="login.php" class="btn btn-primary pull-right"><i class="icon-lock icon-white"></i>&nbsp;Login here!</a>
        <h3>Registration Status</h3>
        
        
    </div>
        <div class="modal-body" style="text-align:center;">
        <div class="row-fluid">
            <div class="span10 offset1">
                <div id="modalTab">
                    <div class="tab-content">
                       <?php

							include('execute/inc/config.inc');
							$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
							// Passkey that got from link 
							$passkey=$_GET['passkey'];
							$tbl_name1="temp_members";
							
							// Retrieve data from table where row that match this passkey 
							$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
							$result1=mysql_query($sql1);
							
							// If successfully queried 
							if($result1){
							
							// Count how many row has this passkey
							$count=mysql_num_rows($result1);
							
							// if found this passkey in our database, retrieve data from table "temp_members_db"
							if($count==1){
							
							$rows=mysql_fetch_array($result1);
							$name=$rows['username'];
							$email=$rows['email'];
							$password=$rows['password']; 
						
							$tbl_name2="perm_members";
							
							// Insert data that retrieves from "temp_members_db" into table "registered_members" 
							$sql2="INSERT INTO $tbl_name2(username, email, password)VALUES('$name', '$email', '".md5($rows['password'])."')";
							$result2=mysql_query($sql2);
							}
							
							// if not found passkey, display message "Wrong Confirmation code" 
							else {
							echo "<h4 class='text-error'>Wrong Confirmation code, Or the Confirmation code was expired.<br/>
							<button class='btn pull-right'><i class='icon-plus'></i>Create Accout!</button></h4>";
							}
							
							// if successfully moved data from table"temp_members_db" to table "registered_members" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db"
							if($result2){
							
							echo "<h4 class='text-success'>Congratulation! Your account has been activated</h4>";
							echo "<p class='lead'>You will redirected in few seconds to login page.</p>";
							
							// Delete information of this user from table "temp_members_db" that has this passkey 
							$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
							$result3=mysql_query($sql3);
							
							}
							
							}
							?>
                           
                   
                     
                    </div>
                </div>
            </div>
        </div>
    </div><div class="clearfix"></div>
    
    </div> <!-- /container -->
    
    
    </div>
   
   

  </body>
</html>

<!-- Localized -->